package com.example.mydemoproject.model;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author LiuZhiYong
 * @description
 * @date 2022-11-13
 **/
public class PropertyUtilsTest {

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
//        Apple apple = new Apple();
//        apple.setName("苹果");
//        apple.setWeight(10);
//        apple.setAges(new ArrayList<>());
//        PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(apple);
//        for (PropertyDescriptor origDescriptor : origDescriptors) {
//            System.out.println(origDescriptor.getName());
//            Class<?> propertyType = origDescriptor.getPropertyType();
//            System.out.println(propertyType.toString());
//            System.out.println(PropertyUtils.isReadable(apple, origDescriptor.getName()));
//            System.out.println(PropertyUtils.getSimpleProperty(apple, origDescriptor.getName()));
//            System.out.println("---------------------------------");
//        }
//        StringBuilder stringBuilder = new StringBuilder();
//        System.out.println(stringBuilder.toString());
//        stringBuilder.append(" and ");
//        stringBuilder.append("query");
//        System.out.println(stringBuilder.toString());
//        String substring = stringBuilder.substring(5);
//        System.out.println(substring);

        String str = "'123'''";
        System.out.println(str);
        String s = str.replace("'", "");
        System.out.println(s);
        System.out.println(str);
    }

    private static void test(Class<?> propertyType) {
        propertyType.toString();

    }


    public static Set<String> getSqlRuleParams(String sql) {
        if(StringUtils.isEmpty(sql)){
            return Collections.emptySet();
        }
        Set<String> varParams = new HashSet<>();
        String regex = "\\#\\{\\w+\\}";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(sql);
        while(m.find()){
            String valueStr = m.group();
            varParams.add(valueStr.substring(valueStr.indexOf("{")+1,valueStr.indexOf("}")));
        }
        return varParams;
    }


}
